package com.dom.domweb.modular.controller;

import com.dom.common.model.vo.sale.*;
import com.dom.domweb.common.RspModel;
import com.dom.domweb.common.TabPager;
import com.dom.domweb.modular.service.AbstractApproveService;
import com.dom.domweb.modular.service.MarketBackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/sale")
public class MarketBackController extends AbstractApproveService{

    @Autowired
    private MarketBackService marketBackService;

    /**
     * 销售退货单查询列表
     * @param limit 每页行数
     * @param page 当前页数
     * @param exchStartDate 交易开始时间
     * @param exchEndDate 交易结束时间
     * @param backStartDate 销售开始时间
     * @param backEndDate 销售结束时间
     * @param custCode 客户编码
     * @param custName 客户名称
     * @param backType 销售类型
     * @return
     */
    @RequestMapping("/getMarketBackList")
    public TabPager getMarketBackList(@RequestParam("limit")int limit,
                                      @RequestParam("page")int page,
                                      @RequestParam("exchStartDate") String exchStartDate,
                                      @RequestParam("exchEndDate")String exchEndDate,
                                      @RequestParam("backStartDate")String  backStartDate,
                                      @RequestParam("backEndDate")String  backEndDate,
                                      @RequestParam("custCode")String  custCode,
                                      @RequestParam("custName")String  custName,
//                                      @RequestParam("sourSaleType")String  sourSaleType,
                                      @RequestParam("backType")String  backType) {
        M059R request = new M059R();
        request.setBackType(backType);
        request.setCustCode(custCode);
        request.setCustName(custName);
//        request.setSourSaleType(sourSaleType);
        request.setExchEndDate(exchEndDate);
        request.setExchStartDate(exchStartDate);
        request.setBackEndDate(backEndDate);
        request.setBackStartDate(backStartDate);
        request.setPn(page);
        request.setPs(limit);
        M059A result = marketBackService.getMarketBackList(request);
        return new TabPager(result.getBackInfoData(),result.getTotalNum());
    }

    /**
     * 销售订新增
     * @param request
     * @return
     */
    @RequestMapping("/insertMarketBack")
    public RspModel insertMarketBack(@RequestBody M050R request){
        String id = marketBackService.insertMarketBack(request);
        return new RspModel(id);
    }

    /**
     * 销售退货单明细查询
     * @param id
     * @return
     */
    @RequestMapping("/toUpdateMarketBackPage")
    public RspModel toUpdateMarketBackPage(@RequestParam("id") String id){
        M053A result = marketBackService.findUpdateMarketBack(id);
        return new RspModel(result);
    }

    /**
     * 销售退货单删除
     * @param id
     * @return
     */
    @RequestMapping("/marketBackDel")
    public RspModel marketBackDel(@RequestParam("id") String id){
        boolean isTure = marketBackService.marketBackDel(id);
        RspModel model = new RspModel("RSP000000","销售退货单删除成功！");
        if(!isTure){
            model.setRspCode("RSP000001");
            model.setRspMsg("销售退货单删除失败！");
        }
        return model;
    }

    /**
     * 销售退货单修改
     * @param request
     * @return
     */
    @RequestMapping("/marketBackModify")
    public RspModel marketBackModify(@RequestBody M052R request){
        return marketBackService.marketBackModify(request);
    }
}
